<?php
include_once('./common.php');
$tid = $_GET['tid'] ? intval($_GET['tid']) : 0;
$aid = $_GET['aid'] ? intval($_GET['aid']) : 0;

if(!empty($aid)&&empty($tid)){
	$query = $_SGLOBAL['db']->query("SELECT a.*,t.* FROM ".tname('article')." AS a LEFT JOIN ".tname('arctype')." AS t ON a.typeid = t.lid WHERE a.arcrank >0 AND a.aid =".$aid);
	$art = $_SGLOBAL['db']->fetch_array($query);
	if(empty($art)){
		showmessage('art_no', 'index.php');
	}
	$typename = $art['typename'];
}elseif(!empty($tid)&&empty($aid)){
	include_once('./source/function_common.php');
	$page = empty($_GET['page'])? 1 : intval($_GET['page']);
	if($page < 1){
		$page=1;
	}
	$perpage = 8; //每页要显示的条数
	$start = ($page-1)*$perpage;
	ckstart($start, $perpage);
	$count = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM ".tname('article')." WHERE arcrank >0 AND typeid =".$tid),0);
	$multi = multi($count, $perpage, $page, "article.php?tid=".$tid);

	$query = $_SGLOBAL['db']->query("SELECT typename FROM ".tname('arctype')." WHERE hide = 0 AND lid =".$tid);
	$val = $_SGLOBAL['db']->fetch_array($query);
	$typename = $val['typename'];
	
	$query2 = $_SGLOBAL['db']->query("SELECT * FROM ".tname('article')." WHERE arcrank >0 AND typeid =".$tid." ORDER BY atime DESC LIMIT ".$start.",".$perpage);
	while($value = $_SGLOBAL['db']->fetch_array($query2)){
		$arc[] = $value;
	}
	if(empty($arc)){
		showmessage('arc_no', 'index.php');
	}
}else{
	showmessage('art_no_id', 'index.php');
}
include template("article");
?>